/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2015年1月4日         cassie
 */

package com.coocaa.launcher.pattern.normal.item;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.coocaa.launcher.framework.launcherhost.view.AppItemView;
import com.coocaa.x.uipackage.SkinManager;
import com.tianci.appstore.R;
import com.tianci.appstore.utils.SkyConstants;

public abstract class AppBaseItemView extends AppItemView {
    protected String titleString;
    protected Drawable removeDrawable;
    protected Drawable addDrawable;
    protected ImageView iconView;
    protected TextView titleView;
    protected static int removeIconResId = R.drawable.remove_hot_item;
    protected static int addIconResId = R.drawable.add_item_icon;

    public AppBaseItemView(Context context, String viewType) {
        super(context, viewType);
        // TODO Auto-generated constructor stub
        removeDrawable = SkinManager.getInstance().getDrawable(null, removeIconResId);
        addDrawable = SkinManager.getInstance().getDrawable(null, addIconResId);
    }

    public void setTitleMarquee(boolean marquee) {
        if (titleView != null)
            titleView.setSelected(marquee);
    }

    public void setEditState(boolean editState) {
        if (titleView == null)
            return;
        ViewGroup.LayoutParams titleParams = titleView.getLayoutParams();
        if (editState) {
            titleView.setCompoundDrawablePadding(SkyConstants.Div(5));
            removeDrawable.setBounds(1, 1, SkyConstants.Div(36), SkyConstants.Div(36));
            titleView.setCompoundDrawables(removeDrawable, null, null, null);
            titleView.setText(SkinManager.getInstance().getString(R.string.remove_hot_item));
            titleParams.width = LayoutParams.WRAP_CONTENT;
        } else {
            titleView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
            titleView.setText(titleString);
            titleParams.width = LayoutParams.MATCH_PARENT;
        }
    }

    public void setAddState(boolean addState) {
        if (titleView == null)
            return;
        ViewGroup.LayoutParams titleParams = titleView.getLayoutParams();
        if (addState) {
            titleView.setCompoundDrawablePadding(SkyConstants.Div(5));
            addDrawable.setBounds(1, 1, SkyConstants.Div(36), SkyConstants.Div(36));
            titleView.setCompoundDrawables(addDrawable, null, null, null);
            titleView.setText(SkinManager.getInstance().getString(R.string.add));
            titleParams.width = LayoutParams.WRAP_CONTENT;
        } else {
            titleView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
            titleView.setText(titleString);
            titleParams.width = LayoutParams.MATCH_PARENT;
        }
    }
}
